﻿using System;
using UnityDemo.AutomaticFactoryCode.AutomaticFactory;
using UnityDemo.LoggingUtility;
using UnityDemo.Models;

/// Code was reworked from Paul Hiles posting at
/// http://www.devtrends.co.uk/blog/using-unity's-automatic-factories-to-lazy-load-expensive-dependencies

namespace UnityDemo.AutomaticFactoryCode
{
    public class AutomaticFactoryDemo : BaseFeatureDemo
    {
        public AutomaticFactoryDemo()
        {
            ISample value = _sampleCollection[1].Value;
        }

        protected override void RegisterSamples()
        {
            _sampleCollection[1] = new Lazy<ISample>(() =>
                                                         {
                                                             LogerInstance.Logger.PriorityMessage(
                                                                 "**Showing a traditional usage of Unity***");

                                                             return new AutomaticFactoryDemoOld();
                                                         });

            _sampleCollection[2] = new Lazy<ISample>(() =>
                                                         {
                                                             LogerInstance.Logger.PriorityMessage(
                                                                 "**Using the new Factory method in Unity***");

                                                             return new AutomaticFactoryDemoNew();
                                                         });
        }
    }
}